package com.aifeng.hassan_food.login

import android.os.Bundle
import com.aifeng.base.BaseActivity
import com.aifeng.common_ui.base.oneClick
import com.aifeng.common_ui.helper.InputLowerToUpper
import com.aifeng.common_ui.helper.textString
import com.aifeng.hassan_food.R
import com.aifeng.utils.bindLifeCycle
import com.aifeng.utils.subscribeByNoError
import com.aifeng.viewmodel.LoginViewModel
import kotlinx.android.synthetic.main.activity_register_code.*
import org.jetbrains.anko.startActivity
import org.koin.androidx.viewmodel.ext.android.getViewModel

class RegisterCodeActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_register_code)
        initTitle(title = "邀请码")
    }

    override fun getViewModel() = getViewModel<LoginViewModel>()

    override fun initTitle(title: String, name: String, divider: Boolean) {
        super.initTitle(title, name, divider)
        register_code.transformationMethod = InputLowerToUpper()

        bt_next.oneClick {
            getViewModel().checkCode(register_code.textString())
                .bindLifeCycle(getLifecycleOwner())
                .subscribeByNoError(
                    event = getViewModel(),
                    onSuccess = {
                        startActivity<RegisterPhoneActivity>(
                            "code" to register_code.textString()
                        )
                    }
                )
        }
    }

}
